<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>箭头函数的应用</title>
    <style>
      #ad {
        width: 200px;
        height: 200px;
        background-color: #58a;
      }
    </style>
  </head>
  <body>
    <div id="ad"></div>
    <script>
      // 需求-1 点击div 2s后颜色变成粉色
      const ad = document.getElementById("ad");
      ad.addEventListener("click", function () {
        /* let _this = this;
        setTimeout(function () {
          _this.style.backgroundColor = "pink";
        }, 2000); */
        setTimeout(() => {
          this.style.backgroundColor = "pink";
        }, 2000);
      });

      /**
       * 箭头函数适合与this无关的回调，定时器，数组的方法回调
       * 箭头函数不适合与this有关的回调，dom事件的回调，对象的方法
       */
    </script>
  </body>
</html>
